<div id="<?php echo $this->fieldId; ?>">
	<input type="hidden" id="<?php echo $this->fieldId; ?>_field" name="<?=$this->fieldName;?>" value="0">
	<div class="mediaList" data-max-items="<?php echo isset($this->params['maxfiles']) ? (int)$this->params['maxfiles'] : 1; ?>"></div>
</div>
<script type="text/javascript">
$(document).ready(function(){

	var target = $('#<?php echo $this->fieldId; ?>').find('.mediaList');
	target.droppable({
		scope: 'mediafile',
		tolerance: 'touch',
		drop: function(ev, ui) {
			var src = ui.draggable;
			addMediaFile($(this), src.attr('src'), src.data('id'));
		}
	}).sortable({
		items: ".mediaThumb",
		handle: 'img',
		tolerance: 'pointer',
		cursor: 'pointer'
	}).disableSelection();

	<?php
	$files = array();
	foreach ($this->data as $obj)
	{
		$files[] = array('id' => $obj->GetId(), 'src' => _ROOT_URL_STATIC.$this->thumbFolder.$obj->GetThumbNail(true));
	}
	?>
	var initFiles = <?php echo Mozg::Lib('Json')->Encode($files); ?>;
	for (x in initFiles)
	{
		addMediaFile(target, initFiles[x].src, initFiles[x].id);
	}
});
</script>